package org.ruoyi.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.ruoyi.common.core.service.OssService;
import org.ruoyi.common.oss.core.OssClient;
import org.ruoyi.common.oss.factory.OssFactory;
import org.ruoyi.service.IHC28Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 首页
 *
 * @author Lion Li
 */
@SaIgnore
@RestController
public class IndexController {

    @Autowired
    private IHC28Service ihc28Service;
    /**
     * 访问首页，提示语
     */
    @GetMapping("/")
    public String index() {
        return "RuoYi AI启动成功！";
    }

    @ApiOperation(value = "查询HC28目录")
    @GetMapping("/queryDirectory")
    public String queryDirectory() {
        OssClient ossClient = OssFactory.instance();
        List<Map<String, Object>> r = ossClient.getSubFileUrls("hc28");

        return JSONUtil.toJsonStr(r);
    }

    @ApiOperation(value = "查询ComfyUI服务地址")
    @GetMapping("/getComfyServer")
    public String getComfyUIServer(@RequestParam("endpoint")String endpoint) {
        return ihc28Service.getComfyUIServer(endpoint);
    }

    @ApiOperation(value = "查询ComfyUI服务WS地址")
    @GetMapping("/getComfyWs")
    public String getComfyUIServerWs() {
        return ihc28Service.getComfyUIServerWs();
    }

    @ApiOperation(value = "提交任务")
    @PostMapping("/submitTask")
    public String submitTask(@RequestBody JSONObject params) {
        return ihc28Service.submit(params);
    }
}
